using System;
using System.Collections.Generic;
using System.Text;

namespace Dominio
{
    public class Release
    {
        private int id;
        private DateTime creationDate;
        private DateTime closeDate;
        private String description;
        private IList<Bug> bugList;
        private String url;
        private int maturity;
        private String version;
        private String state;
        private String country;
        private TestingManager tm;

        #region Contructors
        //contructor used by hibernate
        protected Release()
        { }


        public Release(String closeDate, String creationDate, String description, String version, String url, TestingManager userTm)
        {
            this.closeDate = DateTime.Parse(closeDate);
            this.creationDate = DateTime.Parse(creationDate);
            this.description = description;
            this.version = version;
            this.url = url;
            this.Tm = userTm;
        }
        public Release(int releaseId, String closeDate, String creationDate, String description, String version, String url, TestingManager userTm)
        {
            this.id = releaseId;
            this.closeDate = DateTime.Parse(closeDate);
            this.creationDate = DateTime.Parse(creationDate);
            this.description = description;
            this.version = version;
            this.url = url;
            this.Tm = userTm;
            getMaturity();
        } 
        #endregion


        #region Getters and setters
        public virtual IList<Bug> BugList
        {
            get { return bugList; }
            set { bugList = value; }
        }
        public virtual String Url
        {
            get { return url; }
            set { url = value; }
        }
        public virtual TestingManager Tm
        {
            get { return tm; }
            set { tm = value; }
        }
        public virtual String Country
        {
            get { return country; }
            set { country = value; }
        }
        public virtual String State
        {
            get { return state; }
            set { state = value; }
        }
        public virtual String Version
        {
            get { return version; }
            set { version = value; }
        }
        public virtual String Description
        {
            get { return description; }
            set { description = value; }
        }
        public virtual DateTime CloseDate
        {
            get { return closeDate; }
            set { closeDate = value; }
        }
        public virtual DateTime CreationDate
        {
            get { return creationDate; }
            set { creationDate = value; }
        }
        public virtual int Id
        {
            get { return id; }
            set { id = value; }
        }
        public virtual int Maturity
        {
            get { return maturity; }
            set { maturity = value; }
        } 
        #endregion


        public virtual void getMaturity()
        {
            TimeSpan totalDays = this.closeDate.Subtract(this.creationDate);
            TimeSpan daysLeft = this.closeDate.Subtract(DateTime.Now);
            int mat = (int.Parse(daysLeft.Days.ToString()) * 100) / int.Parse(totalDays.Days.ToString());

            if (mat <=0){
                this.maturity = 0;
            }
            else{
                this.maturity = mat;
            }
            

        }


    }
}
